
<%@page
	import="web_hr.Model,java.util.*,java.sql.*,java.math.*, java.util.Date"%>

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
<style>
#workday {
	width: 330px;
	float: right;
	left: 530px;
	position: absolute;
}

#salary {
	width: 330px;
	margin: 15px auto;
	float: left;
}

#h4 {
	margin-top: 20px;
}
</style>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

	<%
		int totaltime = 0;
		double da = 0.0;
		double ta = 0.0;
		int hra = 300;
		double pre_tax = 0;
		double tax = 0;
		int basictotal = 0;
		double after_tax = 0;
		int payhour = 0;
		
		//把表名hr_time传递给Model，以便对这个表就行操作
		Model time = new Model("hr_time");
		
		//获取从show.jsp中传来的用户名:uname
		String name = (String) request.getParameter("uname");
		System.out.println("name is " + name);
		
		//如果show.jsp中的uname为空，则取登录时session中的用户名：username
		if (name == null) {
			name = (String) request.getSession().getAttribute("username");
		}
		System.out.println("name is " + name);
		
		//获取该用户每小时的基本工资
		String str2 = "select PRIMARY_SALARY from hr_employee where username='"
				+ name + "'";
		System.out.println(str2);
		ResultSet res = time.eQuery(str2);
		if (res != null) {
			res.next();

			payhour = res.getInt("PRIMARY_SALARY");
		}
		//////////////////////////////////////////////////////////////
		time.close();
        //查询hr_time表中是否存在该用户的签到记录、
		int flage = 0;
		String st = "select *from hr_time where username='" + name + "'";
		ResultSet sts = time.eQuery(st);
		if (sts.next()) {
			flage = 1;

			System.out.println("You have recode ");
		} else {
			System.out.println("You have  no  recode ");
		}

		//////////////////////////////////////////////////////////////
		time.close();
		//取出每个月的签到时间总和；
		if (flage == 1) {
			Date nowDate = new Date();
			String form = String.format("%tF", nowDate);
			Calendar cal = Calendar.getInstance();
			//TO_DATE('"+form+"','YYYY-MM-DD'))";
			// int day = cal.get(Calendar.DATE);
			int month = cal.get(Calendar.MONTH) + 1;

			String m = month + "";
			if (month < 10) {
				m = "0" + m;
			}

			int year = cal.get(Calendar.YEAR);
			System.out.println(month);
			System.out.println(year);
			System.out.println(m);
			String str = "select  sum(time) as alltime  from hr_time where  sta  between to_date('"
					+ year
					+ "-"
					+ m
					+ "-"
					+ "01"
					+ " 00:00:00','YYYY-MM-DD HH24:MI:SS')and to_date('"
					+ form
					+ " 23:59:59','YYYY-MM-DD HH24:MI:SS') and username='"
					+ name + "'";
			System.out.println(str);
			ResultSet rs = time.eQuery(str);

			if (rs.next()) {
				totaltime = rs.getInt("alltime") / 60;
				System.out.println(totaltime);

			}
		}

		//////////////////////////////////////////////////////////////
		time.close();
		System.out.println(name);

		//总工资
		basictotal = totaltime * payhour;
		double da1 = basictotal * (0.03);
		BigDecimal b = new BigDecimal(da1);
		da = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

		double ta1 = basictotal * (0.02);
		BigDecimal b2 = new BigDecimal(ta1);
		ta = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
		pre_tax = da + ta + basictotal + hra;
		tax = (pre_tax) * (0.01);
		after_tax = pre_tax - tax;
	%>

	<h4 id="h4">Salary Table</h4>
	<div id="salary">
		<table class="table">
			<tr>
				<th>Head</th>
				<th colspan="2">Account</th>

			</tr>
			<tr>
				<th rowspan="2">Basic</th>
				<td>Pay For Hour</td>
				<td>Work Hours</td>

			</tr>
			<tr>
				<td><%=payhour%></td>
				<td><%=totaltime%></td>
			</tr>
			<tr>
				<th>DA</th>
				<td colspan="2"><%=da%></td>
			</tr>
			<tr>
				<th>TA</th>
				<td colspan="2"><%=ta%></td>
			</tr>
			<tr>
				<th>HRA</th>
				<td colspan="2"><%=hra%></td>
			</tr>
			<tr>
				<th>PRE_TAX</th>
				<td colspan="2"><%=pre_tax%></td>
			</tr>
			<tr>
				<th>TAX</th>
				<td colspan="2"><%=tax%></td>
			</tr>
			<tr>
				<th>AFTTER_TAX</th>
				<td colspan="2"><%=after_tax%></td>
			</tr>
		</table>
	</div>
	<div id="workday">
		<jsp:include page="workday.jsp" flush="true">
			<jsp:param name="salaryName" value="<%=name%>" />
		</jsp:include>
	</div>
</body>
</html>